<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />
		<link href="../css/mui.css" rel="stylesheet" />
		<script src="../js/mui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/myurl.js" type="text/javascript" charset="utf-8"></script>
		<style>
			.area {
				margin: 20px auto 0px auto;
			}

			.mui-input-group:first-child {
				margin-top: 20px;
			}

			.mui-input-group label {
				width: 22%;
			}

			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}

			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}

			.mui-content-padded {
				margin-top: 25px;
			}

			.mui-btn {
				padding: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group" action="/user/info" method="post">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='account' name="userid" type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id='password' name="pwd" type="password" class="mui-input-clear mui-input"
						placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>确认</label>
					<input id='password_confirm' type="password" class="mui-input-clear mui-input" placeholder="请确认密码">
				</div>
				<div class="mui-input-row">
					<label>邮箱</label>
					<input id='email' type="email" name="email" class="mui-input-clear mui-input" placeholder="请输入邮箱">
				</div>
			</form>
			<div class="mui-content-padded">
				<button id='reg' class="mui-btn mui-btn-block mui-btn-primary">注册</button>
			</div>
			<div>
				<p id="message" style="color: red;text-align: center;font-size: 1.25rem;"></p>
			</div>

		</div>


	</body>

	<script type="text/javascript">
	

	    const emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	    const accountReg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/
	    const passwordReg = /^[a-zA-Z]\w{5,17}$/
	    mui('#account')[0].addEventListener('blur', function() {
	    		if (this.value == '') {
	    			mui('#message')[0].innerText = '账号未输入'
	    		} else {
	    			if (!accountReg.exec(this.value)) {
	    				mui('#message')[0].innerText = '账号格式不正确'
	    			}
	    		}
	    
	    	}
	    
	    )
	    
	    
	    mui('#password')[0].addEventListener('blur', function() {
	    		if (this.value == '') {
	    			mui('#message')[0].innerText = '密码未输入'
	    		} else {
	    			if (!passwordReg.exec(this.value)) {
	    				mui('#message')[0].innerText = '密码格式不正确'
	    			}
	    		}
	    
	    	}
	    
	    )
	    mui('#email')[0].addEventListener('blur', function() {
	    		if (this.value == '') {
	    			mui('#message')[0].innerText = '邮箱未输入'
	    		} else {
	    			if (!emailReg.exec(this.value)) {
	    				mui('#message')[0].innerText = '邮箱格式不正确'
	    			}
	    		}
	    	}
	    
	    )
	    
	    mui('#account')[0].addEventListener('input',()=>{
	    	mui('#message')[0].innerText=''
	    })
	    mui('#password')[0].addEventListener('input',()=>{
	    	mui('#message')[0].innerText=''
	    })
	    mui('#email')[0].addEventListener('input',()=>{
	    	mui('#message')[0].innerText=''
	    })
	    
	    
	    mui("#reg")[0].addEventListener('tap', () => {
	    
	    	if (!accountReg.exec(mui('#account')[0].value)) {
	    		mui('#message')[0].innerText = '请输入4-16位以字母开头的账号'
	    		return false
	    	}
	    	if (!passwordReg.exec(mui('#password')[0].value)) {
	    		mui('#message')[0].innerText = '请输入6-18位以字母开头的密码'
	    		return false
	    	}
	    	if (!emailReg.exec(mui('#email')[0].value)) {
	    		mui('#message')[0].innerText = '邮箱格式不正确'
	    		return false
	    	}
	    
	    
	    	if (mui('#password')[0].value == mui('#password_confirm')[0].value) {
	    		
	    			
	    		mui.ajax(myurl+'/user/info',{
	    			data:{
	    				userid:mui('#account')[0].value,
	    				pwd:mui('#password')[0].value,
	    				email:mui('#email')[0].value
	    			},
	    			dataType:'json',
	    			type:'post',
	    			timeout:7000,
	    			success:function(res){
						console.log(res);
	    				if(res.code==1001) {
							mui('#message')[0].innerText = res.message
						}
	    				if(res.code==1000){
							mui.confirm(res.message,function(){
								mui.back()
							})
						}
	    			}
	    			
	    		})
	    		
	    		
	    	} else {
	    		mui.alert('密码不一致', '警告')
	    		return false
	    	}
	    
	    })
	
		
	</script>

</html>
